function KaoQInKaRenYuan(cwasid){
	//初始化表格
	$('#KaoQinRenYuandg').datagrid({
	    url:'KaoQinRenYuan',
	    queryParams:{
	    	CWASID:cwasid
	    },
	    columns:[[
	    	{field:'CWASID',checkbox:true,width:1,title:'考勤编号',align:'center',hidden:true},
			{field:'EMPID',title:'员工id',width:1,align:'center',hidden:true},
			{field:'EMPNAME',title:'员工姓名',width:1,align:'center'},
			{field:'DEPTID',title:'部门id',width:1,align:'center',hidden:true},
			{field:'DEPTNAME',title:'部门',width:1,align:'center'},
			{field:'SHFID',title:'班次id',width:1,align:'center',hidden:true},
			{field:'SHFNAME',title:'班次',width:1,align:'center'},
			{field:'TEMID',title:'班组id',width:1,align:'center',hidden:true},
			{field:'TEMNAME',title:'班组',width:1,align:'center'},
			{field:'SHFREM',title:'班次时间',width:2,align:'center'},
			{field:'KPRTIME',title:'加入时间',width:2,align:'center',
				formatter: function(value,row,index){
					if(!isNaN(value)){
						return "";
					}
					return new Date(value).getFullYear() + '-' + (new Date(value).getMonth() + 1) + '-' + new Date(value).getDate() + ' ' + new Date(value).getHours() + ':' + new Date(value).getMinutes() + ':' + new Date(value).getSeconds();
				}
			}
	    ]],
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
}

$(function(){
	//初始化表格
	$('#KaoQindg').datagrid({
	    url:'KaoQin',
	    /* queryParams:{
	    	deptno:10
	    }, */
	    columns:[[
	    	{field:'CWASID',checkbox:true,width:1,title:'考勤编号',align:'center',hidden:true},
			{field:'DEPTID',title:'部门id',width:1,align:'center',hidden:true},
			{field:'DEPTNAME',title:'部门',width:1,align:'center'},
			{field:'TEMID',title:'班组id',width:1,align:'center',hidden:true},
			{field:'TEMNAME',title:'班组',width:1,align:'center'},
			{field:'SHFID',title:'班次id',width:1,align:'center',hidden:true},
			{field:'SHFNAME',title:'班次',width:1,align:'center'},
			{field:'SHFREM',title:'班次时间',width:2,align:'center'},
			{field:'RSNID',title:'原因id',width:1,align:'center',hidden:true},
			{field:'RSNREASON',title:'考勤原因',width:1,align:'center'},
			{field:'EMPID',title:'员工id',width:1,align:'center',hidden:true},
			{field:'EMPNAME',title:'变更人',width:1,align:'center'},
			{field:'CWASTIME',title:'变更时间',width:2,align:'center',
				formatter: function(value,row,index){
					return new Date(value).getFullYear() + '-' + (new Date(value).getMonth() + 1) + '-' + new Date(value).getDate() + ' ' + new Date(value).getHours() + ':' + new Date(value).getMinutes() + ':' + new Date(value).getSeconds();
				}
			},
			{field:'CWASREM',title:'备注',width:1,align:'center'}
	    ]],
	    toolbar:'#KaoQintb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
	
	//双击行事件
	$("#KaoQindg").datagrid({
		//rowData是当前选中行的数据，是json字符串格式
		onDblClickRow:function(rowIndex,rowData){
			KaoQInKaRenYuan(rowData["CWASID"]);
			$(".panel-title").text("考勤卡 "+rowData["CWASID"]+" 下的人员");
			$("#KaoQinRenYuanwin").window("open");
		}
	});
	
	
	//点击提交
	$("#updateCWA").click(function(){
		var temid = $("#KaoQinBanZu").val();
		if(temid==null || temid=="null" || temid==""){
			return alert("请选择班组部门！");
		}
		var cwasid = $("#KaoQinCWASID").val();
		var shfid = $("#KaoQinBanCi").val();
		if(shfid==null || shfid=="null" || shfid==""){
			return alert("请选择班次！");
		}
		var empid = $(".He_text_t").attr("id");
		var rsnid = $("#KaoQinYuanYin").val();
		if(rsnid==null || rsnid=="null" || rsnid==""){
			return alert("请选择原因！");
		}
		var cwasrem = $("#KaoQinCWASREM").val();
		
//		alert(cwasid+" "+deptid+" "+temid+" "+shfid+" "+rsnid+" "+cwasrem);
		$.ajax({
			url:"updateKQK",
			type:"post",
			data:{"cwasid":cwasid,"temid":temid,"shfid":shfid,"empid":empid,"rsnid":rsnid,"cwasrem":cwasrem},
			success:function(data){
				$('#KaoQindg').datagrid('reload');
			}
		});
		
		//清空表单
		$("#CWASID").val("");
		$("#CWASREM").val("");
		
		
		$("#KaoQinwin").window("close");
	});
	
//	//双击行事件
//	$("#KaoQindg").datagrid({
//		//rowData是当前选中行的数据，是json字符串格式
//		onDblClickRow:function(rowIndex,rowData){
//			$("#KaoQinwin").window("open");
//			$("#KaoQinDept").find("option[value='"+rowData["DEPID"]+"']").prop("selected",true);
//			$("#KaoQinBanZu").find("option[value='"+rowData["TEMID"]+"']").prop("selected",true);
//			$("#KaoQinBanCi").find("option[value='"+rowData["SHFID"]+"']").prop("selected",true);
//			$("#KaoQinYuanYin").find("option[value='"+rowData["RSNID"]+"']").prop("selected",true);
//			$("#KaoQinCWASREM").val(rowData["CWASREM"]);
//			$("#KaoQinCWASID").val(rowData["CWASID"]);
//		}
//	});
	
	//显示
	$("#KaoQinadd").click(function(){
		$('#KaoQinBanZu').combobox({
			url:'BanZucsh',
			valueField:'TEMID',
			formatter:function(row){
	           row.TEMNAME = row.TEMNAME+"  "+row.DEPTNAME;
	           return row.TEMNAME;
	        },
	        textField:"TEMNAME"
		});
		
		$('#KaoQinBanCi').combobox({
			url:'BanCi',
			valueField:'SHFID',
			formatter:function(row){
	               row.SHFNAME = row.SHFNAME+"  "+row.SHFREM;
	               return row.SHFNAME;
	        },
	        textField:"SHFNAME"
		});
		
		$('#KaoQinYuanYin').combobox('reload');
		
		$("#KaoQinCWASID").val("");
		$("#KaoQinCWASREM").val("");
		$("#KaoQinwin").window("open");
	});
});